$().ready(function(){
	$(".input").each( function(){
		$(this).bind("click",function(){postInfo(this);});
	});
});

function postInfo(obj){
	//alert($(obj).attr("field"));
	var flag = $(obj).attr("field");
	if("username" == flag){
		postUsernameInfo(obj);
	}else if("password" == flag){
		postPasswordInfo(obj);
	}else{
		postEmailInfo(obj);
	}
}

function postUsernameInfo(obj){
	var username = $("#username").val();
	$.post(APP+"/ajax/saveinfo",{field: $(obj).attr("field") , value: username } ,function (data) { show(data,obj); });
}

function postPasswordInfo(obj){
	var oldpassword = $("#oldpassword").val();
	var password = $("#newpassword1").val();
	var password2 = $("#newpassword2").val();
	
	$.post(APP+"/ajax/saveinfo",{field: $(obj).attr("field") , oldpassword: oldpassword , password: password , password2: password2 } ,function (data) { show(data,obj); });
}

function postEmailInfo(obj){
	var email = $("#email").val();
	$.post(APP+"/ajax/saveinfo",{field: $(obj).attr("field") , value: email } ,function (data) { show(data,obj); });
}

function show(data,obj){
	if ("success" == data){
		msg(obj,"修改成功");
	}else{
		msg(obj,data);
	}
}